<%@ page language = "java" %>
<%@ page import = "java.util.*" %>
<%@ page import = "edu.colorado.karl.login.ChangePassword" %>
<%@ page import = "javax.servlet.http.Cookie" %>

<link rel="Stylesheet" type="text/css" media="Screen" charset="utf-8" href="css/common.css"/>

<%@ include file = "header.jspf" %>

<html>
<title>changing password...</title>
<body>

<%
ChangePassword c = ChangePassword.getChangePassword();
String new_pass = request.getParameter("new_password");
String conf = request.getParameter("confirm");

cookies = request.getCookies();

//look for a cookie containing a SoftCORE session ID
if(cookies != null)
{
  for(i = 0; i < cookies.length; i++)
  {
    tempstr = cookies[i].getName();
    if(tempstr.compareTo("SOFTCORE_SESSION") == 0)
    {
      //extract the session ID
      sessionID = Integer.parseInt(cookies[i].getValue());

      //check if the session ID is currently valid
      if(a.isActive(sessionID))
      {
        name = a.getUsername(sessionID);
      }
      else
      {
%>

        Error, you must be logged in to change a password.
        <meta http-equiv=REFRESH content=0;url=index.jsp>

<%
      }
    }
  }
}

if(new_pass.compareTo(conf) == 0)
{
  if((new_pass.length()) < 6 || (new_pass.length() > 12))
  {
%>

    <br>Error, new password must be 6 - 12 characters long.
    <br><a href=change_password.jsp>return to change password page</a>

<%
  }

  else
  {
    c.sqlConnect();
    c.changePass(name,new_pass);
%>

    Password successfully changed.<BR>
    <meta http-equiv=REFRESH content=0;url=index.jsp>

<%
  }
}

else
{
%>

  <br>Error, new password and confirm fields do not match.
  <br><a href=change_password.jsp>return to change password page</a>

<%
}

%>

<%@ include file = "footer.jspf" %>
